package com.simple.util.base.extend.page;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: simple_tools
 * @description: 分页工具类
 * @author: ChenWenLong
 * @create: 2019-10-22 11:20
 **/
public class PageUtil {

    //具体的数据
    private List data;
    //总数据量
    private Integer totalCount;
    //总页数
    private Integer totalPage;
    //上一页
    private Integer prevPage;
    //下一页
    private Integer nextPage;

    //当前页
    protected Integer currentPage = 1;

    //每页显示的数据大小
    protected Integer pageSize = 5;

    public Integer getStart() {
        return (currentPage - 1) * pageSize;
    }

    public PageUtil() {
    }

    /**
     * 构建分页大小的功能
     *
     * @param data        分页总数据
     * @param totalCount  总条数
     * @param currentPage 当前页
     * @param pageSize    页面大小
     */
    public PageUtil(List data, Integer totalCount, Integer currentPage, Integer pageSize) {
        this.data = data;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize :
                this.totalCount / this.pageSize + 1;
    }

    public static PageUtil empty() {
        return new PageUtil(new ArrayList(), 0, 0, 0);
    }

    public List getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(Integer prevPage) {
        this.prevPage = prevPage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}
